<template>
	<view class="detail-view">
		<view class="top-bar"><uni-navbar :fixed="true" :back="true" color="#fff" title="答复内容"></uni-navbar></view>

		<view class="detail-info">
			<view class="info-title">
				<view class="title-top">{{ title }}</view>
			</view>
		</view>

		<view class="form-box">
			<u-form :model="form" ref="uForm">
				<u-form-item class="form-item" label="办结时间"><date-time-picker placeholder="请选择办结时间" :defaultValue="endTime" fields="day" @change="timeChange($event, 'endTime')"></date-time-picker></u-form-item>
				<u-form-item class="form-item" required label="延期理由" label-position="top" prop="returnRemark"><u-input v-model="form.returnRemark" type="textarea" input-align="left" placeholder="请输入延期理由" :clearable="false" :height="160" /></u-form-item>
			</u-form>

			<view class="fiexd-btm" v-if="$sysBtns('tagtqk')"><u-button type="error" @click="confirm">提交</u-button></view>
		</view>
	</view>
</template>

<script>
import dateTimePicker from '@/components/uni-datetime-picker';
import { mapState } from 'vuex';
export default {
	components: {
		dateTimePicker
	},
	data() {
		return {
			title: '',

			endTime: '',

			form: {
				motionId: null,
				applyUser: null,
				applyLatestReplyTime: null,
				returnRemark: null
			},
			rules: {
				returnRemark: [
					{
						required: true,
						message: '请输入延期理由',
						trigger: 'change'
					}
				]
			},

			play: false
		};
	},
	onLoad(option) {
		this.loadLogin();
		this.title = option.title;
		if (option && option.motionId) {
			this.form.motionId = option.motionId;
			this.form.deptId = option.deptId;
		}
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	computed: {
		...mapState(['userInfo'])
	},
	methods: {
		loadLogin() {
			if (this.userInfo.Authorization) {
				this.clientCode = this.userInfo.sysUser.clientCode;
				this.userId = this.userInfo.sysUser.id;

				this.form.applyUser = this.userId;
			} else {
				this.$logout();
			}
		},
		timeChange({ date, dt }, idx) {
			this[idx] = date.year + '-' + date.month2 + '-' + date.day2;
		},
		confirm() {
			this.$refs.uForm.validate((valid) => {
				if (!valid) {
					return false;
				} else {
					if (this.endTime == '') {
						this.$msg('申请办结时间不能为空');
						return false;
					}

					this.form.applyLatestReplyTime = this.endTime;

					let data = {};
					data = {
						clientCode: this.clientCode,
						currentUserId: this.userId,
						fileList: this.fileList,
						motionHandlerChange: this.form
					};
					this.$request('/motion/handler/change/apply/delay', data).then((res) => {
						this.$msg(res.msg);
						setTimeout(() => {
							let pre = this.$prePage();
							if (pre && pre.loadData) {
								pre.loadData('refresh');
							}
							uni.navigateBack();
						}, 500);
					});
				}
			});
		}
	}
};
</script>

<style lang="scss">
.detail-view {
	background-color: #fff;
}

.detail-info {
	.info-title {
		margin-bottom: 0;
	}
}

.info-h2 {
	padding: 0 30upx;
	font-size: 17px;
	font-weight: bold;
	color: #ce1617;
	line-height: 88upx;
	background-color: #f9fafc;
}

.info-inner {
	display: flex;

	.item {
		width: 50%;
	}
}

.form-box {
	.form-item {
		@include mp-flex;
		border-top: 20upx solid #f5f7fa;
	}
}

.fiexd-btm {
	position: static;
	padding: 30upx;
}
</style>
